package leetcode_2401_2500;

public class LeeCode_2483 {
    public static void main(String[] args) {
//        System.out.println(bestClosingTime("YYNY"));
        System.out.println(bestClosingTime("YYYY"));
    }
    private static int bestClosingTime(String customers) {
        int n = customers.length();
        int[][] sum = new int[n + 1][2];
        for (int i = 1; i <= n; i++) {
            int ye = customers.charAt(i - 1) == 'Y' ? 1 : 0;
            int no = customers.charAt(i - 1) == 'N' ? 1 : 0;
            sum[i][0] = sum[i - 1][0] + no;
            sum[i][1] = sum[i - 1][1] + ye;
        }
        int ans = Integer.MAX_VALUE, res = 0;
        for (int i = 0; i <= n; i++) {
            int t = sum[i][0] + sum[n][1] - sum[i][1];
            if (t < ans){
                ans = t;
                res = i;
            }
        }
        return res;
    }
}
